home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / cheetah.zip / CPUTZC.C < prev    next >
C/C++ Source or Header  |  1992-08-18  |  4KB  |  115 lines

  1. /* cputzc.c  -  Drawing image in ZCompact format.
  2.  *
  3.  * CHAINED mode version. For mode 13h (MCGA), C4 on (CHAINED).
  4.  * NOTE that in this mode BPERROW is a permanent constant, and always equal to
  5.  * BPERROW_CHAINED.
  6.  *
  7.  * Uses following coding method:
  8.  *
  9.  * Line    ends by a 0, 0 (color code = 0, counter = 0)
  10.  * Picture ends by rows counter.
  11.  *
  12.  *     +7-------------------6+5----------------------0+
  13.  *     | counter (1 till 3)  |  color code (0 - 63)   |
  14.  *     +---------------------+------------------------+
  15.  * or
  16.  *     +7-6+5------------0+    +7---------------------0+
  17.  *     | 0 | color code   |    |  counter              |
  18.  *     +---+--------------+    +-----------------------+
  19.  *
  20.  * Functions:
  21.  *      CputZCompact().
  22.  * See Also: uputc.c
  23.  * Portability: BORLANDC
  24.  *                                      (c) erdy 1992
  25.  * $Header: $
  26.  */
  27. #pragma inline
  28. #include "far.h"
  29. #include "vgaprefx.h"
  30. #include "vgadrv.h"
  31. #include "screen.h"
  32.  
  33. #ifdef ZC_PREPARED
  34.         void CputZCompact(char far *image, int mask, int offset, int rows)
  35. #else
  36.         void CputZCompact(char far *image, int x, int y, int rows)
  37. #endif ZC_PREPARED
  38. {
  39.     _CX = rows;
  40.         _ES = Scdraw_seg;
  41.  
  42. #       ifdef ZC_PREPARED
  43.         asm mov di, offset;
  44.         asm mov ax, mask;
  45. #       else  ZC_PREPARED
  46.         asm mov ax, y;          /* Get argument */
  47.                 asm mov dx, BPERROW_CHAINED;
  48.         asm mul dx;
  49.  
  50.         asm mov di, x;          /* Get argument */
  51.         asm add di, ax;
  52. #       endif ZC_PREPARED
  53.  
  54.     asm push ds;
  55.     asm lds si, image;
  56.     asm cld;
  57.         asm push bp;
  58.     /*
  59.      * Scanline loop. CX contains nrows.
  60.      */
  61. Loop:
  62.                 asm mov dx, cx;                    /* Loop counter */
  63.         asm mov bp, di;                    /* Save DI */
  64.  
  65.         for (;;) {
  66.             asm lodsb;              /* al <- ds:[si++]; get next byte */
  67.             asm mov bl, al;         /* Save color code */
  68.  
  69.             asm rol al, 1;          /* Get counter */
  70.                         asm rol al, 1;          /* = shr al, 6 */
  71.                         asm and ax, 3;          /* ah = 0, al &= 3 */
  72.             asm jne short OKCounter;
  73.                 asm lodsb;      /* Long counter */
  74.                 if (_AL == 0) { /* End of this scanline */
  75. #if 0
  76.                     if (_BL == 0)   /* Next scan line */
  77.                         break;
  78.  
  79.                     asm mov ax, ds;
  80.                     if (_BL == 1) { /* Next colormap */
  81.                                                 asm add ax, 4; /* Shift to next colormap */
  82.                                                 asm sub si, 0x40; /* Shift to 4 paragraphs size */
  83.                     }
  84.                     if (_BL == 2) { /* Previous colormap */
  85.                                                 asm sub ax, 4; /* Shift to next colormap */
  86.                                                 asm add si, 0x40; /* Shift to 4 paragraphs size */
  87.                     }
  88.                     asm mov ds, ax;
  89. #endif
  90.                     break;
  91.                 }
  92. OKCounter:
  93.             if (_BL == 0) {         /* Zero color code -> skipping */
  94.                 asm add di, ax; /* Advance the index */
  95.                 continue;
  96.             }
  97.             asm mov cx, ax;         /* Save length */
  98.             /*
  99.              * Color map table must reside at segment:0.
  100.              */
  101.                         asm and bx, 0x3F;               /* Mask off color code */
  102.                         asm mov al, [bx];   /* Map color code */
  103. /*asm mov al, bl; /* */
  104.             asm rep stosb;               /* Write colors */
  105.             continue;
  106.         }
  107.                 asm mov di, bp;
  108.                 asm add di, BPERROW_CHAINED;
  109.                 asm mov cx, dx;
  110.         asm loop Loop;
  111.  
  112.         asm pop bp;
  113.     asm pop ds;
  114.     return;
  115. }